package edu.gdin.ecommerce.util;

import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;

import edu.gdin.ecommerce.model.DicDetail;

public class DicConverter {

	@SuppressWarnings("unchecked")
	public static String dicMapConvert(String key, Object value) {
		Map<String, Object> application = ActionContext.getContext().getApplication();
		Map<String, Map<String, String>> dicMap = (Map<String, Map<String, String>>) application.get("dicMap");
		if(dicMap != null && dicMap.size() != 0) {
			return dicMap.get(key).get(value.toString());
		} else {
			return key + ":" + value.toString();
		}
	}
	
	@SuppressWarnings("unchecked")
	public static String dicsConvert(String key, Object value) {
		Map<String, Object> application = ActionContext.getContext().getApplication();
		Map<String, List<DicDetail>> dics = (Map<String, List<DicDetail>>) application.get("dics");
		if(dics != null && dics.size() != 0) {
			List<DicDetail> details = dics.get(key);
			for (DicDetail d : details) {
				if(d.getValue().equals(value.toString())) {
					return d.getName();
				} 
			}
		}
		return key + ":" + value.toString();
	}
	
	
}
